EEL_MODS	+= uboot

PHONY-uboot += ub-%
ub-%: $(BUILD_DEPS)
	$(EELQ2)$(MAKE) $(JOB_OPT) \
		-C $(S_UB_DIR) \
		ARCH=$(UB_ARCH) \
		CROSS_COMPILE=$(TC_PREFIX) \
		O=$(O_UB_DIR) \
		$(patsubst ub-%,%,$@)

$(eval $(call deftargets_git,uboot,UB))
$(eval $(call deftargets_download,uboot,UB,$$(UB_PKG),v$$(UB_VERSION)))

PHONY-uboot += uboot
uboot: $(BUILD_DEPS)
uboot: uboot-prepare
uboot: uboot-defconfig
	$(EELQ2)$(MAKE) $(JOB_OPT) \
		-C $(S_UB_DIR) \
		ARCH=$(UB_ARCH) \
		CROSS_COMPILE=$(TC_PREFIX) \
		O=$(O_UB_DIR) \
		$(UB_TARGETS)

PHONY-uboot += uboot-defconfig uboot-menuconfig uboot-savedefconfig
uboot-defconfig: uboot-prepare ub-$(UB_CONFIG)
uboot-menuconfig: ub-menuconfig

uboot-savedefconfig: ub-savedefconfig
ifneq ($(UB_SAVECONF),defconfig)
	$(EELQ5)mkdir -p $(EEL_CHG_DIR)/$(UB_VER_DIR)/configs
	$(EELQ)cp $(O_UB_DIR)/defconfig \
		$(S_UB_DIR)/configs/$(UB_SAVECONF)
	$(EELQ)cp $(O_UB_DIR)/defconfig \
		$(EEL_CHG_DIR)/$(UB_VER_DIR)/configs/$(UB_SAVECONF)
else
	@echo "UB_SAVECONF is defconfig !!!
endif

$(O_UB_DIR)/.config:
	$(EELQ5)$(MAKE_THIS) uboot-defconfig

$(UB_ELF) $(UB_IMAGE) $(O_UB_DIR)/System.map:
	$(EELQ5)$(MAKE_THIS) uboot

PHONY-uboot += uboot-dis uboot-dis-force
uboot-dis:
	$(EELQ5)$(MAKE_THIS) $(O_UB_DIR)/u-boot.dis

$(O_UB_DIR)/u-boot.dis: $(UB_ELF)
	$(EELQ5)$(MAKE_THIS) uboot-dis-force

uboot-dis-force: $(UB_ELF)
	$(EELQ2)$(TC_PREFIX)objdump $(OBJDUMP_FLAGS) \
		$(UB_ELF) \
		> $(O_UB_DIR)/u-boot.dis
	@echo "Disassemble: $(O_UB_DIR)/u-boot.dis"
